home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / util / cli / LibMon.lha / Src / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-28  |  1.9 KB  |  94 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/execbase.h>
  5. #include <clib/exec_protos.h>
  6.  
  7. #include <stdio.h>
  8.  
  9. #include "global.h"
  10. #include "break.h"
  11. #include "libinfo.h"
  12. #include "output.h"
  13. #include "list.h"
  14.  
  15. extern struct ExecBase *SysBase;
  16.  
  17. /*
  18. ** List the specified library
  19. */
  20. void ListLib(STRPTR LibName)
  21. {
  22.   /* Well, at least we don't have to flush the bloody thing... */
  23.   struct Library *Library;
  24.   struct LibInfo *LibInfoItem = NULL;
  25.   
  26.   Forbid();  /* Yeah, boring old system hoggery */
  27.   
  28.   Library = (struct Library *)FindName(&SysBase->LibList,LibName);
  29.   if (Library)
  30.   {
  31.     /* Found ya! */
  32.     LibInfoItem = AddLibInfoItem(NULL,Library);  /* Save the relevent info */
  33.   }
  34.       
  35.   Permit();
  36.   
  37.   if (Library)
  38.   {
  39.     /* Library exists, so must the LibInfoItem... */
  40.     if (LibInfoItem)
  41.     {
  42.       OutputLibInfo(LibInfoItem);
  43.       FreeVec((APTR)LibInfoItem);
  44.     }
  45.     
  46.     /* And if it doesn't, our friend the memory error is here */
  47.     else
  48.     {
  49.       fputs("Error: Not enough memory.\n",stderr);
  50.       clean_exit(20);
  51.     }
  52.   }
  53.   else
  54.     /* The library was not present in memory */
  55.     OutputLibNotFound(LibName);
  56. }
  57.     
  58. /*
  59. ** List all libraries in memory
  60. */
  61. void ListLibs(void)
  62. {
  63.   /* Finally, the LAST ONE!!! */
  64.   struct List *LibInfoList;
  65.   struct LibInfo *LibInfoItem;
  66.   
  67.   /* Cool, Deep Purple J-File */
  68.   
  69.   LibInfoList = BuildLibInfoList();
  70.   
  71.   if (!LibInfoList)
  72.   {
  73.     /* This can't happen.  Must be a memory problem... */
  74.     /* (woa, Deja Vu!) */
  75.     fputs("Error: No more memory.\n",stderr);
  76.     clean_exit(20);
  77.   }
  78.  
  79.   OutputLibInfoHeader();
  80.   LibInfoItem = (struct LibInfo *)LibInfoList->lh_Head;  
  81.   while (LibInfoItem->li_Node.ln_Succ)
  82.   {
  83.     OutputLibInfo(LibInfoItem);
  84.     LibInfoItem = (struct LibInfo *)LibInfoItem->li_Node.ln_Succ;
  85.     if (CTRL_C)
  86.     {
  87.       fputs(BREAK_TXT,stderr);
  88.       break;
  89.     }
  90.   }
  91.   
  92.   KillLibInfoList(LibInfoList);
  93. }
  94.